package logic

import (
	"context"
	"errors"
	"house_srv/models/mysql"

	"house_srv/housesrv"
	"house_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type InfoHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewInfoHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoHouseLogic {
	return &InfoHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *InfoHouseLogic) InfoHouse(in *housesrv.InfoHouseRequest) (*housesrv.InfoHouseResponse, error) {
	// todo: add your logic here and delete this line
	var house mysql.House
	err := house.InfoHouse(int(in.Id))
	if err != nil {
		logx.Error("房源详情展示失败")
		return nil, errors.New("房源详情展示失败")
	}
	if house.ID == 0 {
		logx.Error("该房源不存在")
		return nil, errors.New("该房源不存在")
	}
	return &housesrv.InfoHouseResponse{
		Name:    house.Name,
		Address: house.Address,
		Types:   house.Types,
		Size:    float32(house.Size),
		Price:   float32(house.Price),
	}, nil
}
